package top.xzxsrq.fileviewutils.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.xzxsrq.fileviewutils.entity.DownloadTaskSearch;
import top.xzxsrq.fileviewutils.service.DownloadService;
import top.xzxsrq.web.utils.AjaxResult;

@RestController
@RequestMapping("/download")
public class DownloadController {
    @Autowired
    private DownloadService downloadService;

    @PostMapping("/getDownloadListType")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult getDownloadListType() {
        return downloadService.getDownloadListType();
    }

    @PostMapping("submitDownload")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult submitDownload(@RequestBody JSONObject jsonObject) {
        return downloadService.submitDownload(jsonObject);
    }

    @PostMapping("getDownloadList")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult getDownloadList(@RequestBody DownloadTaskSearch downloadTaskSearch, int pageNum, int pageSize) {
        return downloadService.getDownloadList(downloadTaskSearch,pageNum,pageSize);
    }

    @PostMapping("getDownloadDetails")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult getDownloadDetails(String downloadId) {
        return downloadService.getDownloadDetails(downloadId);
    }

    @PostMapping("delDownload")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult delDownload(String downloadId) {
        return downloadService.delDownload(downloadId);
    }
    @PostMapping("downloadAgain")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult downloadAgain(String downloadId) {
        return downloadService.downloadAgain(downloadId);
    }
    @PostMapping("threadInfo")
    @PreAuthorize("hasAnyRole('initAdmin')")
    public AjaxResult threadInfo() {
        return downloadService.threadInfo();
    }
    @PostMapping("deleTheard")
    @PreAuthorize("hasAnyRole('initAdmin')")
    public AjaxResult deleTheard(@RequestBody String threadId) {
        return downloadService.deleTheard(threadId);
    }
    @PostMapping("urlParsing")
    @PreAuthorize("hasAnyRole('admin','initAdmin','downloadPage')")
    public AjaxResult urlParsing(@RequestBody JSONObject jsonObject) {
        return downloadService.urlParsing(jsonObject);
    }
}
